******SET YOUR DIRECTORY to ...\replication


use "rawdata\BaumSnow\msa-to-placex.dta", clear

rename msa2 original_fipsMSA
g FMSA = original_fipsMSA

rename placefips original_FPLACE
g FPLACE = original_FPLACE
sort FMSA
 

replace FMSA = 730 if original_fipsMSA == 733

replace FMSA = 740 if original_fipsMSA == 743
drop if areaname == "MA, Yarmouth Port CDP"
replace FPLACE = 3600 if areaname == "MA, Barnstable Village CD"

replace FMSA = 1120 if original_fipsMSA == 1123

replace FMSA = 1305 if original_fipsMSA == 1303

replace FMSA = 3280 if original_fipsMSA == 3283

replace FPLACE = 35000 if original_fipsMSA == 3600

replace FMSA = 4240 if original_fipsMSA == 4243

replace FPLACE = 46027 if areaname =="KY, Lexington-Fayette"

replace FMSA = 5480 if original_fipsMSA == 5483

replace FMSA = 5520 if original_fipsMSA == 5523

replace FMSA = 6320 if original_fipsMSA == 6323

replace FMSA = 6400 if original_fipsMSA == 6403

replace FMSA = 6480 if original_fipsMSA == 6483 

drop if areaname == "CA, Alameda city"
drop if areaname == "CA, Berkeley city"

replace FMSA = 8000 if original_fipsMSA == 8003


*****ADD FMSA THAT FOR BAUM-SNOW DOESN'T HAVE
inp
. 34 . "NJ, Newark" . 5640 51000
end

inp
. 6 . "CA, Oakland" . 5775 53000
end

inp
. 34 . "NJ, Bergen-Passaic" . 875 57000
end

inp
. 8 . "CO, Boulder" . 1125 7850
end

inp
. 18 . "IN, Gary" . 2960 27000
end

inp
. 34 . "NJ, Jersey City" . 3640 36000
end

inp
. 34 . "NJ, Middlesex-Somerset-Hunterdon" . 5015 82000
end

inp
. 34 . "NJ, Monmouth-Ocean" . 5190 18130
end

inp
. 48 . "TX, Brazoria" . 1145 56348
end

inp
. 9 . "CT, Bridgeport" . 1160 8000
end

inp
. 23 . "MA, Brockton" . 1200 9000
end

inp
. 9 . "CT, Danbury" . 1930 18430
end

inp
. 25 . "MA, Fitchburg-Leominster" . 2600 23875
end

inp
. 25 . "MA, Lawrence" . 4160 34550
end

inp
. 25 . "MA, Lowell" . 4560 37000
end

inp
. 33 . "NH, Nashua" . 5350 50260
end

inp
. 25 . "MA, New Bedford" . 5400 45000
end

inp
. 33 . "NH, Portsmouth-Rochester" . 6450 62900
end

inp
. 9 . "CT, Stamford-Norwalk" . 8040 73000
end

inp
. 9 . "CT, Waterbury" . 8880 80000
end

inp
. 25 . "MA, Worchester" . 9240 82000
end

save "rawdata\Bridge\list city centers.dta", replace


***********************************

use "rawdata\Bridge\bridge.dta", clear

****ADD FMSA MISSING IN UCR DATASET
replace FMSA = 580 if FCOUNTY == 81 & STATE=="AL"

replace FMSA = 1890 if FCOUNTY == 3 & STATE=="OR"

replace FMSA = 2030 if FCOUNTY == 79  & STATE=="AL"
replace FMSA = 2030 if FCOUNTY == 103 & STATE=="AL"

replace FMSA = 2620 if FCOUNTY == 5 & STATE=="AZ"

replace FMSA = 2995 if FCOUNTY == 77 & STATE=="CO"

replace FMSA = 3285 if FCOUNTY == 35 & STATE=="MS"
replace FMSA = 3285 if FCOUNTY == 73 & STATE=="MS"
replace FMSA = 3285 if FCOUNTY == 111 & STATE=="MS"

replace FMSA = 3600 if FCOUNTY == 109 & STATE=="FL"
replace FMSA = 3600 if FCOUNTY == 89 & STATE=="FL"
replace FMSA = 3600 if FCOUNTY == 31 & STATE=="FL"
replace FMSA = 3600 if FCOUNTY == 19 & STATE=="FL"
replace FMSA = 3600 if FCOUNTY == 3 & STATE=="FL"

replace FMSA = 5140 if FCOUNTY == 63 & STATE=="MT"

save "rawdata\Bridge\bridge_corrected.dta", replace



*********
use  "rawdata\bridge_corrected.dta", clear

set obs `=_N+1'
replace STATE = "IN" if _n==_N
replace COUNTY = "Marion"  if _n==_N
replace AGENCY = "Indianapolis"  if _n==_N
replace FSTATE = 18   if _n==_N
replace FCOUNTY = 97  if _n==_N
replace PLACENM = "Indianapolis"  if _n==_N
replace FMSA = 3480  if _n==_N
replace V3 = "INIPD00"  if _n==_N
replace GOVNAME = "Indianapolis City"  if _n==_N
replace GOVTYPE = 2  if _n==_N
replace UCORE = "Y"  if _n==_N

merge n:1 FMSA using "rawdata\Bridge\list city centers.dta"
g city_center= 0 if _merge==3
drop _merge 


merge n:1 FMSA FPLACE using "rawdata\Bridge\list city centers.dta"
replace city_center= 1 if _merge!=1

replace FSTATE = statefips if _merge==2

saveold "rawdata\Bridge\bridge_final.dta", version(12) replace





